﻿@{
    ViewBag.Title = "手术可预约时间";
}

@Styles.Render("~/Content/js/Calendario/calendar.css")
@Styles.Render("~/Content/js/Calendario/custom_2.css")

<div class="wrap">
    <div class="doctor-timemgt-page">
        <div class="doctor-timemgt-page">
            <br />
            <div class="container">
                <section class="main">
                    <div class="custom-calendar-wrap">
                        <div id="custom-inner" class="custom-inner">
                            <div class="custom-header clearfix">
                                <nav>
                                    <span id="custom-prev" class="custom-prev"></span>
                                    <span id="custom-next" class="custom-next"></span>
                                </nav>
                                <h2 id="custom-month" class="custom-month"></h2>
                                <h3 id="custom-year" class="custom-year"></h3>
                            </div>
                            <div id="calendar" class="fc-calendar-container"></div>
                        </div>
                    </div>
                </section>
            </div>
            <br />
            <div class="mgntimedes">
                <p>
                    <span></span>
                    <a href="#">已开放预约</a>
                </p>
                <p>
                    <span></span>
                    <a href="#">当前日期</a>
                </p>

            </div>
        </div>
    </div>

    @Html.Hidden("gaptime", (string)ViewBag.gaptime)
    @Html.Hidden("gaptimeid", (string)ViewBag.gaptimeid)


</div>


@section scripts
{
    <script src="~/Content/js/Calendario/modernizr.custom.63321.js"></script>
    <script src="~/Content/js/Calendario/jquery.calendario.js"></script>
    <script src="~/Content/js/Calendario/data.js"></script>

    <script type="text/javascript">
        $(function () {

            var transEndEventNames = {
                'WebkitTransition': 'webkitTransitionEnd',
                'MozTransition': 'transitionend',
                'OTransition': 'oTransitionEnd',
                'msTransition': 'MSTransitionEnd',
                'transition': 'transitionend'
            },
                transEndEventName = transEndEventNames[Modernizr.prefixed('transition')],
                $wrapper = $('#custom-inner'),
                $calendar = $('#calendar'),

                cal = $calendar.calendario({
                    onDayClick: function ($el, $contentEl, dateProperties) {

                        if ($contentEl.length > 0) {
                            showEvents($contentEl, dateProperties);
                        }
                        var _selectime = $el.find(".fc-date").attr("date");
                        if ($el.find(".fc-date").attr("date-status") == "0") {
                            layer.open({
                                content: '确定开放当天的预约吗？',
                                btn: ['确定', '取消'],
                                shadeClose: false,
                                yes: function () {
                                    $.post("/doccenter/timemanager/", { gaptime: _selectime }, function (data) {

                                        ///设置当天预约
                                        $el.css({ "background": "#72A000" });
                                        $el.find(".fc-date").attr("date-status", "1");
                                        $el.find("span").css({ "color": "#fff" });
                                        layer.open({ content: '设置成功！', time: 1 });
                                    });
                                }
                            });
                        } else {
                            //暂时不让其取消，关联着患者的预约信息
                            //layer.open({
                            //    content: '确定取消当天的预约吗？',
                            //    btn: ['确定', '取消'],
                            //    shadeClose: false,
                            //    yes: function () {
                            //        $.post("/doccenter/edittimemanager/", { id: $el.find(".fc-date").attr("date-index") }, function (data) {
                            //            $el.find(".fc-date").attr("date-status", "0");
                            //            layer.open({ content: '取消成功！', time: 1 });
                            //        });
                            //    }
                            //});
                        }

                    },
                    caldata: codropsEvents,
                    displayWeekAbbr: true
                }),
                $month = $('#custom-month').html(cal.getMonthName()),
                $year = $('#custom-year').html(cal.getYear());

            $('#custom-next').on('click', function () {
                cal.gotoNextMonth(updateMonthYear);
            });
            $('#custom-prev').on('click', function () {
                cal.gotoPreviousMonth(updateMonthYear);
            });

            function updateMonthYear() {
                $month.html(cal.getMonthName());
                $year.html(cal.getYear());
            }

         
        });
    </script>
}
